## ----loadlib,echo=FALSE,message=FALSE,warning=FALSE----------------------
### Load libraries
library(reshape)
library(plyr)
library(ascii)
library(mclogit)
library(countrycode)
capwords <- function(s, strict = FALSE) {
         cap <- function(s) paste(toupper(substring(s, 1, 1)),
                       {s <- substring(s, 2); if(strict) tolower(s) else s},
                                  sep = "", collapse = " " )
         sapply(strsplit(s, split = " "), cap, USE.NAMES = !is.null(names(s)))
     }

latex.output <- FALSE


## ----data,echo=FALSE,message=FALSE,warning=FALSE-------------------------
### Read the data in
dat <- read.csv("final_data_for_replication_PSB_regulation_28April 2014.csv",
	header=TRUE)
dat$Country <- capwords(tolower(countrycode(dat$iso3c,"iso3c","country.name")))	


## ----tab1,echo=FALSE,message=FALSE,warning=FALSE,results='asis'----------
### Table 1: Prizes by country by festival
tab1 <- with(dat,
	aggregate(value,list(Country=Country,Prize=Prize),sum))
tab1 <- cast(tab1,Country~Prize)
tab1 <- tab1[order(rowSums(tab1[,-1]),decreasing=TRUE),]
print(ascii(tab1,
	include.rownames = FALSE,
	digits=0,
	caption = "*Table 1*: Prizes won by country"),type="pandoc")


## ----tab2,echo=FALSE,message=FALSE,warning=FALSE,results='asis'----------
### Table 2: Summary statistics

the.vars <- c("domestic.market","pay.hh.pct","hhi","spend.percap",
	"home.country.prixitalia","home.country.montecarlo",
	"home.country.montreux","PSB_selfreg","PSB_ministry")

the.labels <- c("Domestic market (USD millions)",
	"Pay-TV (percent)",
	"Concentration (HHI)",
	"PSB spend (USD per head)",
	"Home country (Prix Italia)",
	"Home country (Monte Carlo)",
	"Home country (Montreux)",
	"PSB self-regulates",
	"PSB regulated by ministry")

tab2 <- apply(dat[,the.vars],2,function(x) {
	data.frame(N = length(x),
		Mean = mean(x,na.rm=T),
		Std.Dev. = sd(x,na.rm=T),
		Min = min(x,na.rm=T),
		Max = max(x,na.rm=T))
})
tab2 <- do.call("rbind",tab2)
print(ascii(tab2,
	rownames=the.labels,
	caption = "*Table 2*: Summary statistics"),type="pandoc")


## ----tab3,echo=FALSE,message=FALSE,warning=FALSE,results='hide'----------
### Table 3: Regression results
dat$occasion.num <- as.numeric(dat$occasion)
tab3.mod1 <- mclogit(cbind(value,occasion.num) ~ 
	scale(domestic.market) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap) + home.country.prixitalia + home.country.montecarlo +
	home.country.montreux,
	random = ~1|iso3c,
	data = dat)
tab3.mod2 <- mclogit(cbind(value,occasion.num) ~ 
	scale(domestic.market) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap) + 
	home.country.prixitalia + home.country.montecarlo + home.country.montreux + 
	PSB_selfreg + PSB_ministry,
	random = ~1|iso3c,
	data = dat)


## ----tab3out,echo=FALSE,message=FALSE,warning=FALSE,results='asis'-------
mclogit2df <- function(mod) {
	out <- as.data.frame(summary(mod)$coef)
	out$stars <- symnum(out[,"Pr(>|z|)"], corr = FALSE,
                    cutpoints = c(0,  .001,.01,.05, .1, 1),
                    symbols = c("***","**","*","."," "))
	extras <- data.frame(Estimate = c(NA,NA,NA),
		`Std. Error` = c(mod$deviance,length(mod$fitted.values),mod$N),
		`z value` = c(NA,NA,NA),
		`Pr(>|z|)` = c(NA,NA,NA),
		stars = c(NA,NA,NA))
	names(extras) <- names(out)
	rownames(extras) <- c("Deviance","N (country-festival dyads)","N (prizes)")
	out <- rbind(out,extras)
	out$variable <- rownames(out)
	out <- out[,c(6,1:2,5)]
	return(out)
}

out <- merge(mclogit2df(tab3.mod1),mclogit2df(tab3.mod2),
	by = "variable",all=T,sort=FALSE)
colnames(out) <- c("variable","Beta","SE","Sig.","Beta","SE","Sig.")
variable.order <- c("scale(domestic.market)",
	"scale(pay.hh.pct)",
	"scale(hhi)",
	"scale(spend.percap)",
	"PSB_selfreg",
	"PSB_ministry",
	"home.country.prixitalia",
	"home.country.montecarlo",
	"home.country.montreux",
	"Deviance",
	"N (country-festival dyads)",
	"N (prizes)")
pretty.variables <- c("Domestic market (USD millions)",
	"Pay-TV (percent)",
	"Concentration (HHI)",
	"PSB spend (USD per head)",
	"PSB self-regulates",
	"PSB regulated by ministry",
	"Home country (Prix Italia)",
	"Home country (Monte Carlo)",
	"Home country (Montreux)",
	"Deviance",
	"N (country-festival dyads)",
	"N (prizes)")


out <- out[match(variable.order,out$variable),]

out$variable <- pretty.variables[match(variable.order,out$variable)]
print(ascii(out,
	include.rownames=FALSE,
	caption = "*Table 3*: Conditional logit models",
	tgroup = c("","Model 1","Model 2"),
	col.width = c(.2,.1,.1,.05,.1,.1,.05),
	n.tgroup = c(1,3,3)),type="pandoc")



## ----tab4,echo=FALSE,message=FALSE,warning=FALSE,results='hide'----------
### Table 4: regression results by festival

tab4.mod1 <- mclogit(cbind(value,occasion.num) ~ 
	scale(domestic.market) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap),
	random = ~1|iso3c,
	data = subset(dat,Prize=="Emmies"))

tab4.mod2 <- mclogit(cbind(value,occasion.num) ~ 
	scale(domestic.market) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap) + home.country.montecarlo,
	random = ~1|iso3c,
	data = subset(dat,Prize=="Monte Carlo"))

tab4.mod3 <- mclogit(cbind(value,occasion.num) ~ 
	scale(domestic.market) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap) + home.country.montreux,
	random = ~1|iso3c,
	data = subset(dat,Prize=="Montreux"))

tab4.mod4 <- mclogit(cbind(value,occasion.num) ~ 
	scale(domestic.market) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap) + home.country.montecarlo,
	random = ~1|iso3c,
	data = subset(dat,Prize=="Prix Italia"))


## ----tab4out,echo=FALSE,message=FALSE,warning=FALSE,results='asis'-------
out <- merge(
	merge(mclogit2df(tab4.mod1),
		mclogit2df(tab4.mod2),by="variable",all=T,sort=FALSE),
	merge(mclogit2df(tab4.mod3),
		mclogit2df(tab4.mod4),by="variable",all=T,sort=FALSE),
	by="variable",all=TRUE,sort=FALSE)

colnames(out) <- c("variable",rep(c("Beta","SE","Sig."),4))

out <- out[match(variable.order,out$variable),]
out$variable <- pretty.variables[match(variable.order,out$variable)]

out <- subset(out,!is.na(variable))
print(ascii(out,
	include.rownames=FALSE,
	caption = "*Table 4*: Models by festival",
	tgroup = c("","Emmies","Monte Carlo","Montreux","Prix Italia"),
	n.tgroup = c(1,rep(3,4))),type="pandoc")



## ----tab5,echo=FALSE,message=FALSE,warning=FALSE,results='hide'----------
### Table 5: Delete-one-jackknife results
holder <- vector("list",length(unique(dat$iso3c)))
for (omitted.country in unique(dat$iso3c)) {
	pos <- which(unique(dat$iso3c) == omitted.country)
	tmp.mod <- mclogit(cbind(value,occasion.num) ~ 
		scale(domestic.market) + scale(pay.hh.pct) + scale(hhi) + 
		scale(spend.percap),
		random = ~1|iso3c,
		data = subset(dat,iso3c != omitted.country))
	holder[[pos]] <- data.frame(variable = rownames(summary(tmp.mod)$coef),
		omitted.country = omitted.country,
		zscore = summary(tmp.mod)$coef[,"z value"])
}

### Now get the maximum and minimum for each variable
### First, convert list to data frame
holder <- do.call("rbind",holder)
minmax.df <- ddply(holder,.(variable),function(df){ 
	min.pos <- which.min(df$zscore)
	max.pos <- which.max(df$zscore)
	df <- df[c(min.pos,max.pos),]
	df$type <- c("minimum","maximum")
	df
})

minmax.df <- cbind(minmax.df[which(minmax.df$type=="minimum"),],
	minmax.df[which(minmax.df$type!="minimum"),-1])
minmax.df <- minmax.df[,c(1:3,5:6)]
names(minmax.df) <- c("variable","Country omitted","Minimum z-score","Country omitted","Maximum z-score")


minmax.df <- minmax.df[match(variable.order,minmax.df$variable),]
minmax.df$variable <- pretty.variables[match(variable.order,minmax.df$variable)]
minmax.df <- subset(minmax.df,!is.na(variable))



## ----tab5out,echo=FALSE,message=FALSE,warning=FALSE,results='asis'-------
print(ascii(minmax.df,
	caption = "*Table 5*: Jackknife tests",
	include.rownames=FALSE),type="pandoc")


## ----tab6,echo=FALSE,message=FALSE,warning=FALSE,results='hide'----------
### Table 6: Alternate specification
tab6.mod1 <- mclogit(cbind(value,occasion.num) ~ 
	scale(pop) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap) + home.country.prixitalia + home.country.montecarlo +
	home.country.montreux,
	random = ~1|iso3c,
	data = dat)
out <- mclogit2df(tab6.mod1)


## ----tab6out,echo=FALSE,message=FALSE,warning=FALSE,results='asis'-------
variable.order <- c("scale(pop)",
	"scale(pay.hh.pct)",
	"scale(hhi)",
	"scale(spend.percap)",
	"PSB_selfreg",
	"PSB_ministry",
	"home.country.prixitalia",
	"home.country.montecarlo",
	"home.country.montreux",
	"Deviance",
	"N (country-festival dyads)",
	"N (prizes)")
pretty.variables <- c("Population",
	"Pay-TV (percent)",
	"Concentration (HHI)",
	"PSB spend (USD per head)",
	"PSB self-regulates",
	"PSB regulated by ministry",
	"Home country (Prix Italia)",
	"Home country (Monte Carlo)",
	"Home country (Montreux)",
	"Deviance",
	"N (country-festival dyads)",
	"N (prizes)")



colnames(out) <- c("variable",rep(c("Beta","SE","Sig."),1))

out <- out[match(variable.order,out$variable),]
out$variable <- pretty.variables[match(variable.order,out$variable)]

out <- subset(out,!is.na(variable))
print(ascii(out,
	caption = "*Table 6*: Alternative specification",
	include.rownames=FALSE),type="pandoc")



## ----taba1,echo=FALSE,message=FALSE,warning=FALSE,results='hide'---------
### The language factor in success
tabA1.mod1 <- mclogit(cbind(value,occasion.num) ~ 
	scale(domestic.market) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap) + home.country.prixitalia + home.country.montecarlo +
	home.country.montreux,
	random = ~1|iso3c,
	data = dat)

tabA1.mod2 <- mclogit(cbind(value,occasion.num) ~ 
	scale(homolingualprods) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap) + home.country.prixitalia + home.country.montecarlo +
	home.country.montreux,
	random = ~1|iso3c,
	data = dat)

tabA1.mod3 <- mclogit(cbind(value,occasion.num) ~ 
	scale(domestic.market) + scale(I(homolingualprods-domestic.market)) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap) + home.country.prixitalia + home.country.montecarlo +
	home.country.montreux,
	random = ~1|iso3c,
	data = dat)


## ----taba1.out,echo=FALSE,message=FALSE,warning=FALSE,results='asis'-----
variable.order <- c("scale(domestic.market)",
	"scale(pop)",
	"scale(homolingualprods)",
	"scale(I(homolingualprods - domestic.market))",
	"scale(pay.hh.pct)",
	"scale(hhi)",
	"scale(spend.percap)",
	"PSB_selfreg",
	"PSB_ministry",
	"home.country.prixitalia",
	"home.country.montecarlo",
	"home.country.montreux",
	"Deviance",
	"N (country-festival dyads)",
	"N (prizes)")
pretty.variables <- c("Domestic market (USD millions)","Population",
	"Homolingual countries' GDP + domestic GDP",
	"Homolingual countries' GDP",
	"Pay-TV (percent)",
	"Concentration (HHI)",
	"PSB spend (USD per head)",
	"PSB self-regulates",
	"PSB regulated by ministry",
	"Home country (Prix Italia)",
	"Home country (Monte Carlo)",
	"Home country (Montreux)",
	"Deviance",
	"N (country-festival dyads)",
	"N (prizes)")


out <- merge(
	merge(mclogit2df(tabA1.mod1),
		mclogit2df(tabA1.mod2),by="variable",all=T,sort=FALSE),
	mclogit2df(tabA1.mod3),
	by="variable",all=TRUE,sort=FALSE)

colnames(out) <- c("variable",rep(c("Beta","SE","Sig."),3))

out <- out[charmatch(variable.order,out$variable),]
out$variable <- pretty.variables[match(variable.order,out$variable)]

out <- subset(out,!is.na(variable))
print(ascii(out,
	include.rownames=FALSE,
	caption = "*Table A1*: Alternate specifications",
	tgroup = c("","Model 1","Model 2","Model 3"),
	n.tgroup = c(1,rep(3,3))),type="pandoc")



## ----taba2,echo=FALSE,message=FALSE,warning=FALSE,results='hide'---------
### The presence (or absence) of countries by years
orig <- read.csv("original-prize-data.csv",header=T)

### Country code is a bit messy
orig$iso3c <- NA
orig$iso3c[which(orig$Prize=="Prix Italia")] <- countrycode(
	orig$Country[which(orig$Prize=="Prix Italia")],
	"country.name","iso3c")
orig$iso3c[which(orig$Prize=="Monte Carlo")] <- countrycode(
	orig$Country[which(orig$Prize=="Monte Carlo")],
	"country.name","iso3c")
orig$iso3c[which(orig$Prize=="Emmies")] <- countrycode(
	orig$Country[which(orig$Prize=="Emmies")],
	"country.name","iso3c")
orig$iso3c[which(orig$Prize=="Montreux")] <- as.character(
	orig$Country[which(orig$Prize=="Montreux")])

orig$iso3c <- factor(orig$iso3c)

### When did each country first appear (i.e., win a prize)
first.appearance <- aggregate(orig$Year,list(iso3c = orig$iso3c),min,na.rm=T)
names(first.appearance)[2] <- "FirstYear"
### Restrict this to countries which appear in our analysis
first.appearance <- subset(first.appearance,iso3c %in% unique(dat$iso3c))

### Create a new data frame which only includes countries 
### after their emergence on to the scene
dat2 <- ddply(dat,.(iso3c),function(df) {
	pos <- which(as.character(first.appearance$iso3c) == as.character(df$iso3c[1]))
	first.year <- first.appearance$FirstYear[pos]
	subset(df,Year >= first.year)
})

### Now re-run the main model with this data-set
tabA2.mod1 <- mclogit(cbind(value,occasion.num) ~ 
	scale(domestic.market) + scale(pay.hh.pct) + scale(hhi) + 
	scale(spend.percap) + home.country.prixitalia + home.country.montecarlo +
	home.country.montreux,
	random = ~1|iso3c,
	data = dat2)



## ----taba2.out,echo=FALSE,message=FALSE,warning=FALSE,results='asis'-----
out <- mclogit2df(tabA2.mod1)
colnames(out) <- c("variable",rep(c("Beta","SE","Sig."),1))

out <- out[match(variable.order,out$variable),]
out$variable <- pretty.variables[match(variable.order,out$variable)]

out <- subset(out,!is.na(variable))
print(ascii(out,
	include.rownames=FALSE,
	caption = "*Table A2*: Serious competitors",
	tgroup = c("","Model 1"),
	n.tgroup = c(1,rep(3,1))),type="pandoc")



